package org.hibiscus.jdp.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.hibiscus.jdp.domain.query.TsdCreateQuery;
import org.hibiscus.jdp.service.DBDeSignService;
import org.hibiscus.jdp.utils.IOUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Description: 数据库设计服务控制器
 *
 * @author 然诺
 * @date 2019/07/22
 */
@Api(tags = "数据库设计服务接口")
@AllArgsConstructor
@RestController
@RequestMapping("/db")
public class DBDeSignController {

	private final DBDeSignService dbDeSignService;

	@ApiOperation(value = "创建数据库表结构文档")
	@PostMapping("/table/structure/document")
	public String createTableStructureDocument(@Valid @RequestBody TsdCreateQuery tsdCreateQuery) {
		return dbDeSignService.createTableStructureDocument(tsdCreateQuery);
	}

	@ApiOperation(value = "下载数据库表结构文档")
	@GetMapping("/table/structure/document")
	public void downloadTableStructureDocument(@RequestParam String fileName) {
		IOUtils.download(dbDeSignService.downloadTableStructureDocument(fileName), fileName);
	}
}
